/** 
 * 包名: package com.raising.system.interceptor; <br/> 
 * 添加时间: 2017年7月28日 下午3:29:00 <br/> 
 */
package com.ferryc.commons.interceptor;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * 类名: LoginInterceptor <br/>
 * 创建者: Ferry Chen. <br/>
 * 添加时间: 2017年7月28日 下午3:29:00 <br/>
 */
public class UrlInterceptor implements HandlerInterceptor {
	/**
	 * 日志对象
	 */
	protected Logger logger = LoggerFactory.getLogger(getClass());

	private static List<String> urlList;

	static {
		urlList = new ArrayList();
		urlList.add("login");
		urlList.add("home");
		urlList.add("login_timeout");
		urlList.add("welcome");
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object paramObject) throws Exception {
		// 得到请求的url
		/*
		 * String url = request.getRequestURI(); // 判断是否是公开 地址
		 * 
		 * for (String openUrl : URL_LIST) { if (url.indexOf(openUrl) >= 0) { //
		 * 如果是公开 地址则放行 return true; } }
		 * 
		 * // 判断用户身份在session中是否存在 Subject subject = SecurityUtils.getSubject();
		 * ShiroUser shiroUser = (ShiroUser) subject.getPrincipal(); //
		 * 如果用户身份在session中存在放行
		 * 
		 * String referrer = request.getHeader("referer"); String basePath =
		 * request.getContextPath();
		 * 
		 * if (referrer == null || referrer.equals("") ||
		 * referrer.lastIndexOf(basePath) == -1) { if (shiroUser != null) {
		 * request.getRequestDispatcher("home").forward(request, response); }
		 * else { response.sendRedirect("login"); } return false; }
		 */

		return true;
	}

	@Override
	public void postHandle(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse, Object paramObject, ModelAndView paramModelAndView)
			throws Exception {
		logger.info("HandlerInterceptor1...postHandle");
	}

	@Override
	public void afterCompletion(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse, Object paramObject, Exception paramException)
			throws Exception {

	}

}
